@extends("admin.layouts.main")
<style>
    .my-ver-align {
        vertical-align: -2px;
    }

    .btn-link {
        color: gray;
    }

    .my-daili {
        position: relative;
    }
</style>
@section("content")
<div class="container-fiuld p-3">
    <div class="card">
        <div class="card-body pt-1">
            <div class="row mt-1 mb-2">
                <div class="col-lg-12 pt-3 pb-3" style="background-color:#F2F2F2">
                    <form class="form-inline position-relative flex-nowrap justify-content-between">
                        <div class="d-flex align-items-center flex-wrap">
                            <select class="form-control" name="search">
                                <option value="">请选择</option>
                                <option value="username" @if($search=='username') selected @endif>用户名</option>
                                <option value="gid" @if($search=='gid') selected @endif>公会ID</option>
                            </select>
                            <input type="text" id="keyword" name="keyword" placeholder="请输入搜索内容" value="{{ $keyword }}"
                                   class="ml-4 mr-5 form-control">
                            <a class="btn btn-primary btn-sm ml-5 mr-3 search text-white">查询</a>
                            <button type="reset" class="btn btn-secondary mr-3 btn-sm">重置</button>
                        </div>
						@if(in_array('guild.create', $menuRule))
                        <a class="btn btn-success btn-sm my-daili" href="{{ route('guild.create') }}">添加公会</a>
						@endif
                    </form>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-12 table-responsive">
                    <table class="table layui-form h6">
                        <thead class="thead-light">
                        <tr class="text-dark">
                            <th>ID</th>
                            <th>公会ID/名称</th>
                            <th>登录用户名</th>
                            <th>公会老板</th>
                            <th>手机</th>
                            <th>座机</th>
                            <th>微信</th>
                            <th>QQ</th>
                            <th>邮箱</th>
                            <th>地址</th>
                            <th>指定客服</th>
                            <th>状态</th>
							@if(in_array('guild.edit', $menuRule) || in_array('guild.anchor', $menuRule))
                            <th>操作</th>
							@endif
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($guildlist as $v)
                        <tr>
                            <td>{{ $v->id }}</td>
                            <td>{{ $v->gid}}/{{$v->gtitle}}</td>
                            <td>{{ $v->username}}</td>
                            <td>{{ $v->boss_name}}</td>
                            <td>{{ $v->mobile}}</td>
                            <td>{{ $v->tel}}</td>
                            <td>{{ $v->wechat}}</td>
                            <td>{{ $v->qq}}</td>
                            <td>{{ $v->email}}</td>
                            <td>{{ $v->address}}</td>
                            <td>{{ $v->kefu}}</td>
                            <td>
								@if(in_array('guild.active', $menuRule))
                                <input data-url="{{ route('guild.active', ['id' => $v->id]) }}" data-type="PATCH" type="checkbox" name="status"
                                       lay-skin="switch" lay-filter="active" lay-text="开启|关闭" @if($v->status==1) checked @endif>
								@else
									@if($v->status==1) 开启 @else 关闭 @endif
								@endif	   
                            </td>
							@if(in_array('guild.edit', $menuRule) || in_array('guild.anchor', $menuRule))
                            <td>
								@if(in_array('guild.edit', $menuRule))
                                <a href="{{ route('guild.edit', ['id' => $v->id]) }}" class="btn btn-primary btn-sm edit">修改</a>
								@endif
								@if(in_array('guild.anchor', $menuRule))
                                <a href="{{ route('guild.anchor', ['gid' => $v->gid]) }}" class="btn btn-primary btn-sm">查看主播</a>
								@endif
                            </td>
							@endif
                        </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <div style="text-align: right;">
            {{ $guild->appends(['search'=>$search, 'keyword' => $keyword])->links('admin.layouts.paginate') }}
        </div>
    </div>
</div>
@endsection

@section("js")
<script type="text/javascript">
    layui.use(['form', 'ori', "laydate"], function () {
        var form = layui.form,
            ori = layui.ori,
            dialog = layui.dialog,
            $ = layui.$,
            laydate = layui.laydate;
        //时间插件
        laydate.render({
            elem: '#test1', //指定元素
            //range: true,
            done: function (val, date, endDate) {
            }
        });
        $('[type=reset]').click(function (e) {
            //$('form')[0].reset();
            e.preventDefault();
            $('[name=search]').val("");
            $('[name=keyword]').val("");
        })
        $('.search').click(function () {
            var search = $('[name="search"]').val();
            var keyword = $("#keyword").val();
            location.href = "{{ route('guild.index') }}" + '?search=' + search + ' &keyword=' + keyword;
        });
        form.on('switch(active)', function (data) {
            var isActive = data.elem.checked, val, _that = $(this);
            val = (isActive === true) ? 1 : 2;
            ori.submit(_that, {field: 'status', val: val}, '', function () {
                _that.prop('checked', !isActive);
                form.render('checkbox');
            })
            return false;
        });
    });
</script>
@endsection
